package com.ce.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.ce.entity.Product;
import com.ce.entity.Provider;
import com.ce.mapper.ProductMapper;
import com.ce.service.ProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author ce
 * @since 2022-01-26
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {
    @Resource
    private ProductMapper mapper;

    @Override
    public List<Product> getList(Product product) {
        QueryWrapper<Product> wrapper = new QueryWrapper<>();
        wrapper.like(StringUtils.isNotEmpty(product.getProductNo()),"product_no",product.getProductNo());
        return mapper.selectList(wrapper);
    }

    @Override
    public Integer deleteById(Integer id) {
        Integer ret = mapper.deleteById(id);
        return ret;
    }

    @Override
    public Map<String, String> addProduct(Product product) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("mode", "insert one product");
        mapper.insert(product);
        return map;
    }

    @Override
    public Map<String, String> updateProduct(Product product) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("mode", "update one product");
        mapper.updateById(product);
        return map;
    }
}
